package com.inxedu.os.edu.controller.course;

import com.inxedu.os.common.util.QiNiuUtil;
import com.inxedu.os.common.util.UploadResult;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

@Controller
@Api(tags = "视频上传工具类接口")
public class VideoController {

    @RequestMapping(value = "/video2",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public UploadResult ss2(MultipartFile uploadfile )throws IOException {

        FileInputStream inputStream = (FileInputStream)uploadfile.getInputStream();

        String saveFileName = UUID.randomUUID().toString().replace("-","");
        UploadResult uploadResult;
        try{
            QiNiuUtil.upload2Qiniu(inputStream, saveFileName);
            uploadResult = new UploadResult(QiNiuUtil.qiniu_img_url_pre +saveFileName, 0, "成功");
        }catch (Exception e){
            uploadResult = new UploadResult(null, 1, "失败");
        }
        return uploadResult;
    }
}
